package com.miplus.ccrm.core.service.conf;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.conf.WfActEditReqVo;
import com.miplus.ccrm.core.controller.vo.conf.WfActionReqVo;
import com.miplus.ccrm.core.controller.vo.conf.WfActionResVo;
import com.miplus.ccrm.core.pojo.FiCreditcases;
import com.miplus.ccrm.core.pojo.WfActions;
import com.miplus.ccrm.core.pojo.WfSteps;
import com.miplus.ccrm.core.mapper.WfActionsMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
* @author pc
* @description 针对表【wf_actions】的数据库操作Service实现
* @createDate 2024-03-10 11:30:51
*/
@Service
public class WfActionsServiceImpl extends MPJBaseServiceImpl<WfActionsMapper, WfActions>
    implements WfActionsService{

    @Override
    public IPage<WfActionResVo> wfActionList(WfActionReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                WfActionResVo.class,
                new MPJLambdaWrapper<WfActions>()
                        .leftJoin(WfSteps.class,"ws",WfSteps::getStepid,WfActions::getNextstepid)
                        .selectAs("ws.name",WfActionResVo::getNextstepname)
                        .selectAll(WfActions.class)
                        .eq("t.stepid",paras.getStepid())
                        .orderByAsc(WfActions::getActionid)
        );
    }

    @Override
    public CmdResVo updateAction(WfActEditReqVo paras)
    {
        WfActions def=new WfActions();
        BeanUtils.copyProperties(paras,def);
        int ret= baseMapper.update(def,new UpdateWrapper<WfActions>()
                .lambda()
                .eq(WfActions::getActionid,paras.getActionid())
        );
        return new CmdResVo(ret,def.getActionid().toString());
    }

    @Override
    public CmdResVo insertAction(WfActEditReqVo paras)
    {
        WfActions def=new WfActions();
        BeanUtils.copyProperties(paras,def);
        int ret= baseMapper.insert(def);
        return new CmdResVo(ret,def.getActionid().toString());
    }

    @Override
    public CmdResVo deleteAction(String id)
    {
        int ret= baseMapper.deleteById(JPubUtils.StringToInt(id));
        return new CmdResVo(ret,id);
    }
}




